//
// Created by QU on 2023/8/17.
//

#ifndef VHDLSENDER_DATAGENERATORFILLER_H
#define VHDLSENDER_DATAGENERATORFILLER_H

#include <stdbool.h>
#include "header.h"

// ---------- block filler ------------

size_t fillBlockWithZero(uint8_t *mallocBuffer, size_t filledSize);

size_t fillBlockWithRandom(uint8_t *mallocBuffer, size_t filledSize);

size_t fillBlockWithSpecificBlock(uint8_t *mallocBuffer, size_t bufferSize, size_t filledSize,
                                  const uint8_t *specificData, size_t specificDataSize);

// ---------- generator ------------

void generateHeader(vcTypeHeader_t *target, enum VC_TYPE vcType, uint16_t logicalChannelID,
                    uint16_t physicalChannelID, uint16_t SQ,
                    size_t frameLength, uint16_t frameNum);

size_t generateData_60a1da8e(uint8_t *mallocBuffer, size_t bufferSize, size_t filledSize);

size_t generateData_00toFF(uint8_t *mallocBuffer, size_t bufferSize, size_t filledSize);

size_t generateData_LowerIncrementHigherLogicalID(uint8_t *mallocBuffer, size_t bufferSize, size_t filledSize,
                                                  uint16_t logicalID);

size_t generateData_ChannelIncrement(uint8_t *mallocBuffer, size_t bufferSize, size_t filledSize, uint16_t logicalID);


// ---------- output buffer filler ------------
size_t outputBufferLoadFiller(const uint8_t buffer[], size_t bufferLength, enum VC_TYPE vcType, uint16_t splitedCols,
                              size_t outBufferOneLineLength, uint8_t outBuffer[splitedCols][outBufferOneLineLength]);


size_t outputBufferHeaderFillerWithIndex(vcTypeHeader_t *headerData, uint16_t splitedCols,
                                         size_t inputBufferOneLineLength,
                                         uint8_t inputBuffer[splitedCols][inputBufferOneLineLength],
                                         size_t targetColFirstFrameIndex);

size_t outputBufferHeaderFiller(vcTypeHeader_t startHeader, enum VC_TYPE vcType, uint16_t splitedCols,
                              size_t inputBufferOneLineLength,
                              uint8_t inputBuffer[splitedCols][inputBufferOneLineLength]);

size_t outputBufferMFIFiller(enum VC_TYPE vcType, uint16_t splitedCols,
                             size_t inputBufferOneLineLength,
                             uint8_t inputBuffer[splitedCols][inputBufferOneLineLength], uint16_t startMFI);


bool outputToFiles(uint16_t splitedCols, size_t inputBufferOneLineLength,
                   uint8_t inputBuffer[splitedCols][inputBufferOneLineLength], uint16_t startPhysicalID);




// ---------- tester ------------
#ifdef TEST_MODE

void testDataGenerator();

#endif //TEST_MODE

#endif //VHDLSENDER_DATAGENERATORFILLER_H
